home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_UMINNgopher.idb / usr / freeware / src / gopher_1.12 / gopher / download.c.z / download.c
C/C++ Source or Header  |  1997-09-09  |  4KB  |  170 lines

  1. /********************************************************************
  2.  * $Author: drich $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1995/10/03 04:08:00 $
  5.  * $Source: /proj/freeware1.0/gopher1.12/src/gopher/RCS/download.c,v $
  6.  * $State: Exp $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: download.c
  14.  * Functions relating to downloading data
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: download.c,v $
  18.  * Revision 1.1  1995/10/03  04:08:00  drich
  19.  * gopher 1.2 check-in
  20.  *
  21.  * Revision 1.4  1993/01/14  21:59:30  lindner
  22.  * Filenames generated for zmodem now are a bit better.. should work better
  23.  * on VMS
  24.  *
  25.  * Revision 1.3  1993/01/12  20:42:04  lindner
  26.  * Added <stat.h> stuff for VMS, also changed text download for VMS from
  27.  * cat to type
  28.  *
  29.  * Revision 1.2  1993/01/11  19:26:56  lindner
  30.  * Mods to make it work under VMS
  31.  *
  32.  * Revision 1.1  1993/01/07  22:47:20  lindner
  33.  * Initial revision
  34.  *
  35.  *
  36.  *********************************************************************/
  37.  
  38.  
  39.  
  40.  
  41. #include "gopher.h"
  42. #ifdef VMS
  43. #include <stat.h>
  44. #else
  45. #include <sys/stat.h>
  46. #endif
  47.  
  48. static char *DLnames[] = {
  49.      "Zmodem",
  50.      "Ymodem",
  51.      "Xmodem-1K",
  52.      "Xmodem-CRC",
  53.      "Kermit",
  54.      "Text",
  55.      NULL
  56.      };
  57.  
  58. static char *DLcmds[] = {
  59.      "sz ",
  60.      "sb ",
  61.      "sx -k ",
  62.      "sx ",
  63.      "kermit -q -s ",
  64. #ifdef VMS
  65.      "type ",
  66. #else
  67.      "cat -v ",
  68. #endif
  69.      NULL
  70.      };
  71.  
  72.  
  73. void
  74. Download_file(gs)
  75.   GopherObj *gs;
  76. {
  77.      char   *titles[10];
  78.      int    choice;
  79.      char   tmpfilename[512], *cp;
  80.      char   command[512];
  81.      int    start, end;
  82.      
  83.      struct stat buf;
  84.  
  85.      switch (GSgetType(gs)) {
  86.      case A_DIRECTORY:
  87.      case A_CSO:
  88.      case A_ERROR:
  89.      case A_INDEX:
  90.      case A_TELNET:
  91.      case A_TN3270:
  92.       CursesErrorMsg("Sorry, can't download that!");
  93.       return;
  94.      }
  95.  
  96.      choice = CURChoice(CursesScreen, GSgetTitle(gs), DLnames, 
  97.             "Choose a download method");
  98.      
  99.      if (choice == -1)
  100.       return;
  101.      
  102.      
  103.      /*** Get a reasonable tmp file name ***/
  104.      cp = GSgetPath(gs);
  105.      if ((cp = strrchr(cp,'/')) != NULL)
  106.       strcpy(tmpfilename, cp+1);
  107.      else
  108.       strcpy(tmpfilename,GSgetTitle(gs));
  109.  
  110. #ifdef VMS
  111.      VMSfile(tmpfilename);
  112. #else
  113.      UNIXfile(tmpfilename);
  114. #endif
  115.  
  116.      for (cp=tmpfilename; *cp != '\0'; cp++) {
  117.       switch (*cp) {
  118.       case ' ':
  119.       case '\"':
  120.       case '\'':
  121.            *cp = '_';
  122.       }
  123.      }
  124.  
  125.      /*** Retrieve the file ***/
  126.      Save_file(gs, NULL, tmpfilename);
  127.  
  128.      /*** Check to see which method they're using to download ***/
  129.      
  130.      if (stat(tmpfilename, &buf) < 0) {
  131.       CursesErrorMsg("File didn't transfer successfully");
  132.       return;
  133.      }
  134.  
  135.      /*** Now start the download ... ***/
  136.      
  137.      strcpy(command, DLcmds[choice]);
  138.      strcat(command, tmpfilename);
  139.      
  140.      CURexit(CursesScreen);
  141.  
  142.      start = time(NULL);
  143.  
  144.      if (choice == 5) {
  145.       printf("Start your capture now...\n\n");
  146.       printf("Press <RETURN> when you're ready\n");
  147.       fflush(stdout);
  148.       getchar();
  149.      } else {
  150.       printf("Start your download now...\n");
  151.       fflush(stdout);
  152.      }
  153.      system(command);
  154.      end = time(NULL);
  155.      if (end == start)
  156.       end++;
  157.      
  158.  
  159.      printf("\nDownload Complete. %d total bytes, %d bytes/sec\n",
  160.         buf.st_size, buf.st_size/(end-start));
  161.  
  162.      printf("Press <RETURN> to continue");
  163.      fflush(stdout);
  164.      getchar();
  165.      CURenter(CursesScreen);
  166.      
  167.      unlink(tmpfilename);
  168.  
  169. }
  170.